/*jslint newcap:true, browser: true, devel: true, bitwise: true, white: true, plusplus: true, nomen:true */
/*global $:true, define:true */

define(['WID/Core/Ajax'], function(Ajax) {
"use strict";

return {
	name:'Ajax', 
	desc:'Its testing ajax helper class',
	
	tests:[
		function toQueryPair() {
			this.expect(Ajax.toQueryPair('a',true)).toBe('a=true');
			this.expect(Ajax.toQueryPair('b','a table')).toBe('b=a%20table');
		},
		
		function toQueryString() {
			this.expect(Ajax.toQueryString({a:true,b:3,c:'a table'})).toBe('a=true&b=3&c=a%20table');
		},
		
		function SyncGet() {
			this.describe('request without params');
			var data;
			Ajax.get('Core/AjaxTestServerSide/SimpleResponse.php',null,function(xhr) {
				data = xhr;
			},function(xhr) {
				data = xhr;
			},false);
				
			this.expect(data).toBeInstanceOf(XMLHttpRequest);
			this.expect(data.responseText).toBe('test');
			this.expect(data.readyState).toBe(4);
			this.expect(data.status).toBe(200);
			this.expect(data.statusText).toBe('OK');
		},
		
		function SyncPost() {
			this.describe('request without params');
			var data;
			Ajax.post('Core/AjaxTestServerSide/SimpleResponse.php',null,function(xhr) {
				data = xhr;
			},function(xhr) {
				data = xhr;
			},false);
				
			this.expect(data).toBeInstanceOf(XMLHttpRequest);
			this.expect(data.responseText).toBe('test');
			this.expect(data.readyState).toBe(4);
			this.expect(data.status).toBe(200);
			this.expect(data.statusText).toBe('OK');
		}
		
	]
};
});
